package app.controlador;

import java.io.DataInputStream;
import java.io.FileInputStream;

import vo.ArticuloVO;

import app.modelo.BusinessdelegateCD;

import com.thoughtworks.xstream.XStream;

import framework.controlador.Controlador;
import framework.modelo.Businessdelegate;
import framework.vista.Vista;

public class ControladorNuevoArticulo extends Controlador
{
	public ControladorNuevoArticulo(Businessdelegate mod, Vista v)
	{
		super(mod, v);
	}
	
	@SuppressWarnings("deprecation")
	public ArticuloVO obtenerNuevoArticuloXML(String absolutePathXML)
	{
		StringBuffer contenido = new StringBuffer();
		ArticuloVO articulovo=null;
		
		try
		{
			FileInputStream fileInputStream=new FileInputStream(absolutePathXML);
			DataInputStream input = new DataInputStream(fileInputStream);
			
			contenido.append(input.readLine());
			contenido.append(input.readLine());
			contenido.append(input.readLine());
			contenido.append(input.readLine());
			contenido.append(input.readLine());
			contenido.append(input.readLine());
			contenido.append(input.readLine());
			contenido.append(input.readLine());
			contenido.append(input.readLine());
			contenido.append(input.readLine());
			contenido.append(input.readLine());
			
			XStream xstream=new XStream();
			xstream.alias("Articulo", ArticuloVO.class);
			articulovo=(ArticuloVO)xstream.fromXML(contenido.toString());
			
			input.close();
		}
		catch(Exception e)
		{
			System.out.println("Error al leer XML nuevoArt");
		}
		
		System.out.println("Se leyo el XML nuevoArt");
		return articulovo;
	}

	// Obtiene articulo desde database
	public ArticuloVO obtenerArticulo(int codigoArticulo)
	{
		return ((BusinessdelegateCD)(this.getModelo())).obtenerArticulo(codigoArticulo);
	}
	
	// Guarda articulo en database
	public void guardarArticulo(ArticuloVO articulovo)
	{
		((BusinessdelegateCD)(this.getModelo())).guardarArticulo(articulovo);
	}
}
